<template>
  <div>
    <div class="register-form">
      <el-input
        v-model="form.name"
        placeholder="输入姓名"
        size="large"
      ></el-input>
      <el-input
        v-model="form.number"
        placeholder="输入学号"
        size="large"
      ></el-input>

      <el-button type="primary" @click="submitHandler">注册账号</el-button>
    </div>
  </div>
</template>
<style scoped>
.register-form {
  margin: 20% auto;
  width: 8rem;
}
.el-input {
  margin-bottom: 1.5rem;
  font-size: 18px;
}
.el-input__inner {
  padding: 15px 15px;
  height: 66px;
}
.el-button {
  width: 3rem;
  font-weight: 500;
  font-size: 20px;
  /* 文字间隔 */
}
</style>
<script>
import { post, get } from "@/utils/request";
export default {
  data() {
    return {
      form: {},
      userid: "",
      userInfo: {},
      username:"",
      usernumber:""
    };
  },
  methods: {
    submitHandler() {
      let url = "http://120.77.41.127:8080/nameUser/saveOrUpdate";
      post(url, this.form).then((resp) => {
        // 提示
        this.$message({ type: "success", message: resp.message });
      });
      console.log(this.form);
      setTimeout(this.getUserInfo(),1000)
      
    },
    async getUserInfo() {
      let url = "http://120.77.41.127:8080/nameUser/query";
      let data = await get(url);
      this.userInfo = data.data;
      console.log(this.userInfo);
      this.userid = this.userInfo[this.userInfo.length - 1].id + 1;
      this.username = this.userInfo[this.userInfo.length - 1].name;
      this.usernumber = this.userInfo[this.userInfo.length - 1].number;

      sessionStorage.setItem("userId", this.userid);
      sessionStorage.setItem("userName", this.username);
      sessionStorage.setItem("userNumber", this.usernumber);
      
      console.log(this.userid);
      console.log(this.username);
      this.$router.replace("/");
    },
  },
};
</script>